import java.util.*;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-11-11
 * Time: 9:55
 */
public class Test {

    public static void main(String[] args) {
        //strStr("mississippi", "issip");
//        boolean b = wordPattern("ccccbb",
//                "s s s s t t");
//        System.out.println(b);
//        Map<String, Integer> map = new HashMap<>();
//        map.put("dsa", map.getOrDefault("dsa", 0) + 1);
//        map.containsKey();
//        List<Integer> list = new ArrayList<>();
//        map.
        reverseStr("abcdefg", 2);
    }

    public static String reverseStr(String s, int k) {
        int len = s.length();
        char[] chs = new char[len];
        int left = 0;
        for(int i = 0; i < len; i++){
            chs[i] = s.charAt(i);
        }
        int flag = 0;
        for(int i = 0; i < chs.length; i++){
            flag++;
            if(flag == 2 * k){
                int right = left + k - 1;
                while(left < right){
                    char tmp = chs[left];
                    chs[left] = chs[right];
                    chs[right] = tmp;
                    left++;
                    right--;
                }
                flag = 0;
                left = i + 1;
            }
        }
        if(left != chs.length){
            int right = left + k - 1;
            while(left < right){
                char tmp = chs[left];
                chs[left] = chs[right];
                chs[right] = tmp;
                left++;
                right--;
            }
        }
        return new String(chs);
    }

    public static boolean wordPattern(String pattern, String s) {
        HashMap<Object, Integer> map1 = new HashMap<>();
        String[] strs = s.split(" ");
        if(pattern.length() != strs.length){
            return false;
        }
        for(int i = 0; i < pattern.length(); i++){
            if(map1.put(pattern.charAt(i), i) != map1.put(strs[i], i)){
                return false;
            }
        }
        return true;
    }

    public static List<Integer> getRow(int rowIndex) {
        int m = (int)Math.pow(2,rowIndex - 1);
        int[][] arr = new int[rowIndex + 1][m];
        for(int i = 0; i <= rowIndex; i++){
            arr[i][0] = 1;
        }
        for(int i = 0; i <= rowIndex; i++){
            int n = (int)Math.pow(2, i);
            for(int j = 1; j < n; j++){
                arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
            }
        }
        List<Integer> lists = new ArrayList<>();
        for(int i = 0; i < m; i++){
            lists.add(arr[rowIndex][i]);
        }
        return lists;
    }

    public static int strStr(String haystack, String needle) {
        int len1 = haystack.length();
        int len2 = needle.length();
        for(int i = 0; i < len1; i++){
            if(haystack.charAt(i) == needle.charAt(0)){
                if(len1 - i < len2){
                    return -1;
                }
                int x = i, y = 0;
                for(; y < len2; ){
                    if(haystack.charAt(x) == needle.charAt(y)){
                        x++;
                        y++;
                    }else {
                        break;
                    }
                }
                if (y == len2){
                    return i;
                }
            }
        }
        return -1;
    }
}
